﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows.Controls;
using System.Windows.Data;
using FinPlusAssembler;
using FinPlusInterfaces;
using System.Xml;

namespace FinPlusCompView
{
    public partial class FinPlusXmlEditor : FinPlusControl
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }
        [State(Test = true)]
        public override string TestString { get { return Adapter.ToString(); } }
        public override IPods Adapter { get { return _pods; } }
        public XmlDocument xmlDocument { get { return _xmldocument; } set { _xmldocument = value; BindXMLDocument(); } }

        private IPods _pods;
        private XmlDocument _xmldocument;

        //construct
        public FinPlusXmlEditor()
        {
            InitializeComponent();
            IsValid = true;
        }

        //common control interface
        public override void Dock(object control, string dock)
        {
            try
            {
                AddPod((IPods)control);
            }
            catch (Exception e)
            {
                IsValid = Level.Error.Log(Id, Config, e.Message, e);
            }
        }

        //private
        private void BindXMLDocument()
        {
            if (_xmldocument == null)
            {
                xmlTree.ItemsSource = null;
                return;
            }

            var provider = new XmlDataProvider() { Document = _xmldocument };
            var binding = new Binding() { Source = provider, XPath = "child::node()" };
            xmlTree.SetBinding(TreeView.ItemsSourceProperty, binding);
        }

        private void AddPod(IPods pods) { _pods = pods; }
    }
}





























































































//Copyright2013<jnrton>AllRightsReserved 
//Contact j.nrton@finpus